/**
 * 
 */
package com.weblists;

import com.weblists.commands.Command;
import com.weblists.commands.ErrorCommand;
import com.weblists.commands.LoginCommand;
import com.weblists.commands.PasswordCommand;
import com.weblists.commands.SignUpCommand;

/**
 * @author Stephen Jennings
 * 
 */
public class CommandFactory {
	private static CommandFactory instance = null;

	protected CommandFactory() {
		// Exists only to defeat instantiation.
	}

	public static CommandFactory getInstance() {
		if (instance == null) {
			instance = new CommandFactory();
		}
		return instance;
	}
	
	public Command getFor(String cmd) {		
		Command theCmd = new ErrorCommand();
		try {
			if (cmd.equals("signup")) {
				theCmd = new SignUpCommand();	
			} else if (cmd.equals("login")) {			
				theCmd = new LoginCommand();
			} else if (cmd.equals("password")) {
				theCmd = new PasswordCommand();
			}
		} catch(NullPointerException npe) {
			// doing nothing here will return the default error command.
		}
		return theCmd;
	}	
}
